
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>绿色医院登录系统</title>
    <style>        body.hospital-login {
        font-family: Arial, sans-serif;
        background-color: #e8f7e4; /* 绿色背景 */
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
        margin: 0;
        overflow: hidden; /* 防止滚动条 */
        animation: fadeIn 1s ease-in-out; /* 添加淡入动画 */
    }

    @keyframes fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }

    .login-container {
        border-radius: 10px;
        box-shadow: 0 0 10px rgba(0,0,0,0.1);
        padding: 20px;
        background-color: white;
        width: 300px;
        position: relative; /* 用于添加动画 */
        animation: slideIn 1s ease-in-out forwards;
    }

    @keyframes slideIn {
        from { transform: translateY(-100%); }
        to { transform: translateY(0); }
    }

    input[type="tel"], input[type="password"] {
        width: 100%;
        padding: 10px;
        margin-bottom: 15px;
        border: 1px solid #90ee90; /* 绿色边框 */
        border-radius: 4px;
        transition: border-color 0.3s; /* 添加边框颜色过渡 */
    }

    input[type="tel"]:focus, input[type="password"]:focus {
        border-color: #00a600; /* 焦点时更亮的绿色 */
    }

    button {
        width: 100%;
        padding: 10px;
        background-color: #007bff; /* 保持原蓝色 */
        color: white;
        border: none;
        cursor: pointer;
        border-radius: 4px;
        transition: background-color 0.3s;
    }

    button:hover {
        background-color: #0056b3;
    }

    .message {
        color: #ff0000; /* 红色错误消息 */
        display: none; /* 初始隐藏 */
        animation: fadeOut 1s ease-in-out forwards 1s; /* 添加淡出动画 */
    }

    .message.visible {
        display: block; /* 显示错误消息 */
    }

    @keyframes fadeOut {
        from { opacity: 1; }
        to { opacity: 0; }
    }

    </style>
</head>
<body class="hospital-login">
<div class="login-container">
    <h2>登录</h2>
    <form id="loginForm">
        <label for="phone">电话号码:</label>
        <input type="tel" id="phone" name="phone" required>
        <label for="password">密码:</label>
        <input type="password" id="password" name="password" required>
        <button type="submit">登录</button>
        <button id="register" style="margin-top: 30px">注册</button>
    </form>
    <p class="message" id="errorMessage"></p>
</div>
<script>
document.getElementById('register').addEventListener('click', function() {
    window.location.href = 'register.html';
})
    document.getElementById('loginForm').addEventListener('submit', function(event) {
    event.preventDefault();

    const phone = document.getElementById('phone').value;
    const password = document.getElementById('password').value;

    fetch('./loginservlet?phone='+phone+'&password='+password, {
        method: 'POST',
    })
        .then(response => {
            if (!response.ok) {
                throw new Error('网络错误');
            }
            return response.text();
        })
        .then(data => {
            console.log(data)
            if (data==="1"||data==="2") {
                if(data==="1"){
                    window.location.href = '/web/admin.html';
                }else{
                    window.location.href = '/web/common.html';
                }
            } else {
                document.getElementById('errorMessage').classList.add('visible'); // 显示错误消息
                document.getElementById('errorMessage').textContent = "该账户未注册";
                setTimeout(() => {
                    document.getElementById('errorMessage').classList.remove('visible'); // 隐藏错误消息
                }, 3000);
            }
        })
        .catch(error => {
            console.error('登录请求失败:', error);
            document.getElementById('errorMessage').classList.add('visible');
            document.getElementById('errorMessage').textContent = '登录失败，请重试';
            setTimeout(() => {
                document.getElementById('errorMessage').classList.remove('visible');
            }, 3000);
        });
});

</script>
</body>
</html>
